package demo;

import demo.channel.AbstractPayChannel;
import demo.channel.impl.PayPalChannel;
import demo.mode.impl.FingerprintMode;
import demo.mode.impl.PasswordMode;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhouWeiBo
 * @create 2022/6/8
 */
public class App {
    public static void main(String[] args) {
        /* 支付渠道+模式这里可以用状态模式来解耦 */
        payController("1","手指",1000L,new PayPalChannel(new FingerprintMode()));

        //payController("1","xxx",1000L,new PayPalChannel(new FingerprintMode()));
        payController("1","密码",1000L,new PayPalChannel(new PasswordMode()));
    }


    public static Map<Long,BigDecimal> productMoneyMap = new HashMap<>();

    static {
        productMoneyMap.put(1000L,new BigDecimal(399));
        productMoneyMap.put(2000L,new BigDecimal(588));
        productMoneyMap.put(3000L,new BigDecimal(999));
        productMoneyMap.put(4000L,new BigDecimal(1));
    }

    /**
     * 模仿Controller
     * @param userId 用户id
     * @param identity 识别信息
     * @param productId 金额
     * @param channel 支付渠道+模式（ 这里可以用状态模式来解耦 ）
     * @return boolean
     */
    public static boolean payController(String userId, Object identity, Long productId, AbstractPayChannel channel){
        // ...省略各种校验
        return channel.pay(userId,identity,productMoneyMap.get(productId));
    }
}
